<?php
class BrandModel extends MongoModel{
	var $table ='brand';
	var $name = '品牌';
	
	public static $VALUE_TYPE = array(
		'brand_flags' 	=> 'int',
		'rank' 			=> 'int'
	);
	
	public static function getOpts($has_null=false, $null_text='--不限制--'){
		$key = 'brand_' . SITE_ID;
		$brands = Yii::app()->cache->get($key);
		if($brands === false){
			$mod = new BrandModel();
			$condition = array('site_id'=>SITE_ID);
			$brands = $mod->find($condition);
			Yii::app()->cache->set($key, $brands);
		}
		if($has_null){
			$opts = array('' => $null_text);
		}else{
			$opts = array();
		}
		foreach ($brands as $_id=>$brand){
			$opts[$_id] = $brand['name'];
		}
		return $opts;
	}
	
	public static function cleanCache(){
		$key = 'brand_' . SITE_ID;
		Yii::app()->cache->delete($key);
	}
}

?>